// components/selectComponent/selectComponent.js
const date = new Date()
const hoursArr = []
const minutes = []
const hours = date.getHours()
const minute = date.getMinutes()


for (let i = 0; i <= 24; i++) {
  hoursArr.push(i)
}

for (let i = 0; i <= 60; i++) {
  minutes.push(i)
}


Component({

  onShareAppMessage() {
    return {
      title: 'picker-view',
      path: 'page/component/pages/picker-view/picker-view'
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {
    nowDate:{
      type:Date
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    hoursArr,
    hours,
    minutes,
    minute,
    value: [hours, minute],
  },


  /**
   * 组件的方法列表
   */
  methods: {
    bindChange(e) {
      const val = e.detail.value
      this.setData({
        hours: this.data.hoursArr[val[0]],
        minute: this.data.minutes[val[1]],
      })
    },

    // 点击保存或取消，触发父组件修改
    exit(e){
      const {flag} = e.target.dataset
      if(flag == 'save'){
        // 格式化date
        let newTime = `${this.data.hours}:${this.data.minute}`
        // 触发父组件的回调
        this.triggerEvent("tapExit",newTime)
      }else if(flag == 'cancel'){
        this.triggerEvent("tapExit",null)
      }
    }
  },

  // 生命周期
  lifetimes:{
    attached(){
    }
  }
})
